package com.autoconfig;

import com.YKFuse.bean.beanprocessor.YKFusePostProcessor;
import com.YKFuse.bean.operation.alert.YKFuseAlertService;
import com.YKFuse.bean.operation.alert.YKFuseAlertServiceDefaultImpl;
import com.YKFuse.bean.operation.pool.YKFusePoolOperation;
import com.YKFuse.bean.operation.pool.YKFusePoolOperationImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yuank
 * @version 1.0.0
 * @date 2025/2/11 14:55:44
 *
 */
//@Lazy -高频使用 不推荐
@Configuration
@EnableConfigurationProperties(YKFuseProperties.class)
public class YkFuseAutoConfiguration {

    // 引入配置文件
    @Bean
    public YKFuseProperties ykFuseProperties() {
        return new YKFuseProperties();
    }

    // 默认告警
    @Bean("defaultAlertServiceImpl")
    public YKFuseAlertService ykFuseAlertService() {
        return new YKFuseAlertServiceDefaultImpl();
    }

//场景 熔断池的告警bean是动态的 我们需要从applicationContext里获取 但applicationContext是在构造器执行完毕后才会出现 以下的方式自然不支持
//@AutoWired可以👆
//    @Bean
//    public YKFusePoolOperation ykFusePoolOperation(YKFuseProperties ykFuseProperties,
//                                                   YKFuseAlertService ykFuseAlertService) {
//        return new YKFusePoolOperationImpl(ykFuseProperties, ykFuseAlertService);
//    }

    // 熔断池
    @Bean
    public YKFusePoolOperation ykFusePoolOperation(YKFuseProperties ykFuseProperties) {
        return new YKFusePoolOperationImpl(ykFuseProperties);
    }

    // 引入bean包装器-beanPostProcessor
    @Bean
    public YKFusePostProcessor ykFusePostProcessor(YKFusePoolOperation ykFusePoolOperation) {
        return new YKFusePostProcessor(ykFusePoolOperation);
    }


}